home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 296_01 / flexdef.h < prev    next >
C/C++ Source or Header  |  1989-10-01  |  18KB  |  486 lines

  1. /*
  2.  *  Definitions for flex.
  3.  *
  4.  * modification history
  5.  * --------------------
  6.  * 02b kg, vp   30sep87  .added definitions for fast scanner; misc. cleanup
  7.  * 02a vp       27jun86  .translated into C/FTL
  8.  */
  9.  
  10. /*
  11.  * Copyright (c) 1987, the University of California
  12.  * 
  13.  * The United States Government has rights in this work pursuant to
  14.  * contract no. DE-AC03-76SF00098 between the United States Department of
  15.  * Energy and the University of California.
  16.  * 
  17.  * This program may be redistributed.  Enhancements and derivative works
  18.  * may be created provided the new works, if made available to the general
  19.  * public, are made available for use by anyone.
  20.  */
  21.  
  22. #include <stdio.h>
  23.  
  24. #include <string.h>
  25. #define bzero(s, n) memset((char *)(s), '\000', (unsigned)(n))
  26.  
  27. /* char *sprintf(); /* keep lint happy */
  28.  
  29.  
  30. /* maximum line length we'll have to deal with */
  31. #define MAXLINE BUFSIZ
  32.  
  33. /* maximum size of file name */
  34. #define FILENAMESIZE 1024
  35.  
  36. #define min(x,y) (x < y ? x : y)
  37. #define max(x,y) (x > y ? x : y)
  38.  
  39. #define true 1
  40. #define false 0
  41.  
  42.  
  43. #ifndef DEFAULT_SKELETON_FILE
  44. #define DEFAULT_SKELETON_FILE "flex.skel"
  45. #endif
  46.  
  47. #ifndef FAST_SKELETON_FILE
  48. #define FAST_SKELETON_FILE "flex.fastskel"
  49. #endif
  50.  
  51. /* special nxt[] action number for the "at the end of the input buffer" state */
  52. /* note: -1 is already taken by YY_NEW_FILE */
  53. #define END_OF_BUFFER_ACTION -3
  54. /* action number for default action for fast scanners */
  55. #define DEFAULT_ACTION -2
  56.  
  57. /* special chk[] values marking the slots taking by end-of-buffer and action
  58.  * numbers
  59.  */
  60. #define EOB_POSITION -1
  61. #define ACTION_POSITION -2
  62.  
  63. /* number of data items per line for -f output */
  64. #define NUMDATAITEMS 10
  65.  
  66. /* number of lines of data in -f output before inserting a blank line for
  67.  * readability.
  68.  */
  69. #define NUMDATALINES 10
  70.  
  71. /* transition_struct_out() definitions */
  72. #define TRANS_STRUCT_PRINT_LENGTH 15
  73.  
  74. /* returns true if an nfa state has an epsilon out-transition slot
  75.  * that can be used.  This definition is currently not used.
  76.  */
  77. #define FREE_EPSILON(state) \
  78.     (transchar[state] == SYM_EPSILON && \
  79.      trans2[state] == NO_TRANSITION && \
  80.      finalst[state] != state)
  81.  
  82. /* returns true if an nfa state has an epsilon out-transition character
  83.  * and both slots are free
  84.  */
  85. #define SUPER_FREE_EPSILON(state) \
  86.     (transchar[state] == SYM_EPSILON && \
  87.      trans1[state] == NO_TRANSITION) \
  88.  
  89. /* maximum number of NFA states that can comprise a DFA state.  It's real
  90.  * big because if there's a lot of rules, the initial state will have a
  91.  * huge epsilon closure.
  92.  */
  93. #define INITIAL_MAX_DFA_SIZE 750
  94. #define MAX_DFA_SIZE_INCREMENT 750
  95.  
  96. /* array names to be used in generated machine.  They're short because
  97.  * we write out one data statement (which names the array) for each element
  98.  * in the array.
  99.  */
  100.  
  101. #define ALIST 'l'    /* points to list of rules accepted for a state */
  102. #define ACCEPT 'a'    /* list of rules accepted for a state */
  103. #define ECARRAY 'e'    /* maps input characters to equivalence classes */
  104. #define MATCHARRAY 'm'    /* maps equivalence classes to meta-equivalence classes */
  105. #define BASEARRAY 'b'    /* "base" array */
  106. #define DEFARRAY 'd'    /* "default" array */
  107. #define NEXTARRAY 'n'    /* "next" array */
  108. #define CHECKARRAY 'c'    /* "check" array */
  109.  
  110. /* NIL must be 0.  If not, its special meaning when making equivalence classes
  111.  * (it marks the representative of a given e.c.) will be unidentifiable
  112.  */
  113. #define NIL 0
  114.  
  115. #define JAM -1    /* to mark a missing DFA transition */
  116. #define NO_TRANSITION NIL
  117. #define UNIQUE -1    /* marks a symbol as an e.c. representative */
  118. #define INFINITY -1    /* for x{5,} constructions */
  119.  
  120. /* size of input alphabet - should be size of ASCII set */
  121. #define CSIZE 127
  122.  
  123. #define INITIAL_MAXCCLS 100    /* max number of unique character classes */
  124. #define MAXCCLS_INCREMENT 100
  125.  
  126. /* size of table holding members of character classes */
  127. #define INITIAL_MAX_CCL_TBL_SIZE 500
  128. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  129.  
  130. #define INITIAL_MNS 2000    /* default maximum number of nfa states */
  131. #define MNS_INCREMENT 1000    /* amount to bump above by if it's not enough */
  132.  
  133. #define INITIAL_MAX_DFAS 1000    /* default maximum number of dfa states */
  134. #define MAX_DFAS_INCREMENT 1000
  135.  
  136. #define JAMSTATE -32766    /* marks a reference to the state that always jams */
  137.  
  138. /* enough so that if it's subtracted from an NFA state number, the result
  139.  * is guaranteed to be negative
  140.  */
  141. #define MARKER_DIFFERENCE 32000
  142. #define MAXIMUM_MNS 31999
  143.  
  144. /* maximum number of nxt/chk pairs for non-templates */
  145. #define INITIAL_MAX_XPAIRS 2000
  146. #define MAX_XPAIRS_INCREMENT 2000
  147.  
  148. /* maximum number of nxt/chk pairs needed for templates */
  149. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  150. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  151.  
  152. #define SYM_EPSILON 0    /* to mark transitions on the symbol epsilon */
  153.  
  154. #define INITIAL_MAX_SCS 40    /* maximum number of start conditions */
  155. #define MAX_SCS_INCREMENT 40    /* amount to bump by if it's not enough */
  156.  
  157. #define ONE_STACK_SIZE 500    /* stack of states with only one out-transition */
  158. #define SAME_TRANS -1    /* transition is the same as "default" entry for state */
  159.  
  160. /* the following percentages are used to tune table compression:
  161.  
  162.  * the percentage the number of out-transitions a state must be of the
  163.  * number of equivalence classes in order to be considered for table
  164.  * compaction by using protos
  165.  */
  166. #define PROTO_SIZE_PERCENTAGE 15
  167.  
  168. /* the percentage the number of homogeneous out-transitions of a state
  169.  * must be of the number of total out-transitions of the state in order
  170.  * that the state's transition table is first compared with a potential 
  171.  * template of the most common out-transition instead of with the first
  172.  * proto in the proto queue
  173.  */
  174. #define CHECK_COM_PERCENTAGE 50
  175.  
  176. /* the percentage the number of differences between a state's transition
  177.  * table and the proto it was first compared with must be of the total
  178.  * number of out-transitions of the state in order to keep the first
  179.  * proto as a good match and not search any further
  180.  */
  181. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  182.  
  183. /* the percentage the number of differences between a state's transition
  184.  * table and the most similar proto must be of the state's total number
  185.  * of out-transitions to use the proto as an acceptable close match
  186.  */
  187. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  188.  
  189. /* the percentage the number of homogeneous out-transitions of a state
  190.  * must be of the number of total out-transitions of the state in order
  191.  * to consider making a template from the state
  192.  */
  193. #define TEMPLATE_SAME_PERCENTAGE 60
  194.  
  195. /* the percentage the number of differences between a state's transition
  196.  * table and the most similar proto must be of the state's total number
  197.  * of out-transitions to create a new proto from the state
  198.  */
  199. #define NEW_PROTO_DIFF_PERCENTAGE 20
  200.  
  201. /* the percentage the total number of out-transitions of a state must be
  202.  * of the number of equivalence classes in order to consider trying to
  203.  * fit the transition table into "holes" inside the nxt/chk table.
  204.  */
  205. #define INTERIOR_FIT_PERCENTAGE 15
  206.  
  207. /* size of region set aside to cache the complete transition table of
  208.  * protos on the proto queue to enable quick comparisons
  209.  */
  210. #define PROT_SAVE_SIZE 2000
  211.  
  212. #define MSP 50    /* maximum number of saved protos (protos on the proto queue) */
  213.  
  214. /* maximum number of out-transitions a state can have that we'll rummage
  215.  * around through the interior of the internal fast table looking for a
  216.  * spot for it
  217.  */
  218. #define MAX_XTIONS_FOR_FULL_INTERIOR_FIT 4
  219.  
  220. /* number that, if used to subscript an array, has a good chance of producing
  221.  * an error; should be small enough to fit into a short
  222.  */
  223. #define BAD_SUBSCRIPT -32767
  224.  
  225. /* absolute value of largest number that can be stored in a short, with a
  226.  * bit of slop thrown in for general paranoia.
  227.  */
  228. #define MAX_SHORT 32766
  229.  
  230.  
  231. /* Declarations for global variables. */
  232.  
  233. /* variables for symbol tables:
  234.  * sctbl - start-condition symbol table
  235.  * ndtbl - name-definition symbol table
  236.  * ccltab - character class text symbol table
  237.  */
  238.  
  239. struct hash_entry
  240.     {
  241.     stru